﻿<UserControl xmlns:controls="clr-namespace:Microsoft.Lync.Controls;assembly=Microsoft.Lync.Controls"  x:Class="WorkItemCollaborator.WICControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:vsfx="clr-namespace:Microsoft.VisualStudio.Shell;assembly=Microsoft.VisualStudio.Shell.10.0" xmlns:src="clr-namespace:WorkItemCollaborator" mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             Name="MyToolWindow">
    <Control.Resources>        
        <src:HtmlToDocumentConverter x:Key="HtmlToDocumentConverter" />
        <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />
        <src:ChangedFieldCollectionToStringConverter x:Key="ChangedFieldCollectionToStringConverter" />        
    	<Style x:Key="titleStyle" TargetType="TextBlock">
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="FontSize" Value="13"/>            
        </Style>

        <Style x:Key="smallTitleStyle" TargetType="TextBlock">
            <Setter Property="FontWeight" Value="Bold"/>
            <Setter Property="Foreground" Value="DimGray"/>
            <Setter Property="VerticalAlignment" Value="Center"/>
            <Setter Property="HorizontalAlignment" Value="Right"/>
        </Style>

        <Style x:Key="textStyleTextBlock" TargetType="TextBlock">
            <Setter Property="Foreground" Value="#333333" />
        </Style>

        <DataTemplate DataType="{x:Type src:HistoryItem}">
            <Border BorderThickness="1" BorderBrush="Gray"
                    Padding="7" Name="border" Margin="3" Width="700" Visibility="{Binding Path=IsVisible, Converter={StaticResource booleanToVisibilityConverter}}">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition/>                        
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150"/>
                        <ColumnDefinition Width="*"/>                        
                    </Grid.ColumnDefinitions>

                    <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0" >
                        <controls:PresenceIndicator ContextualInformation="{Binding Path=HistoryItemContextualInformation}" Source="{Binding Path=Owner.IMSource}" PhotoDisplayMode="Small"  HorizontalAlignment="Left" VerticalAlignment="Center"/>
                        <TextBlock Style="{StaticResource smallTitleStyle}" Text="{Binding Path=Owner.Name}" HorizontalAlignment="Left" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding Path=Owner.Name}" Width="150">                            
                        </TextBlock>
                        <TextBlock  Text="{Binding Path=RevsionDate}" Style="{StaticResource textStyleTextBlock}" HorizontalAlignment="Left" VerticalAlignment="Center"/>
                    </StackPanel>
                    
                    <!--<TextBlock Grid.Row="0" Grid.Column="2" Margin="0,0,8,0"
                               Name="descriptionTitle"
                               Style="{StaticResource smallTitleStyle}">Comments:</TextBlock>-->                    
                    <!--<WebBrowser x:Name="MyWebBrowser" Grid.Row="0" Grid.Column="2"  Width="100" Height="20" >
                        <WebBrowser.Tag>
                            <MultiBinding Converter="{StaticResource HtmlToDocumentConverter}" Mode="OneWay">
                                <Binding RelativeSource="{x:Static RelativeSource.Self}" />
                                <Binding Path="HistoryComment"/>
                            </MultiBinding>
                        </WebBrowser.Tag>
                    </WebBrowser>-->
                    <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center">
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock Grid.Row="0" Grid.Column="2" Margin="0,0,8,0"                               
                               Style="{StaticResource textStyleTextBlock}">Review Comments:</TextBlock>
                            <TextBlock Grid.Row="0" Grid.Column="1" ToolTipService.ShowDuration="10000"
                                Text="{Binding Path=HistoryComment}" 
                                Style="{StaticResource smallTitleStyle}">
                                    <TextBlock.ToolTip>
                                    <ToolTip DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">       
                                        <!--<WebBrowser x:Name="HistoryCommentBrowser" Width="Auto" Height="Auto" >
                                            <WebBrowser.Tag>
                                                <MultiBinding Converter="{StaticResource HtmlToDocumentConverter}" Mode="OneWay"> 
                                                    <Binding RelativeSource="{x:Static RelativeSource.Self}" />
                                                    <Binding Path="HistoryComment"/>
                                                </MultiBinding>
                                            </WebBrowser.Tag>
                                        </WebBrowser>-->
                                          <TextBlock  Text="{Binding Path=HistoryComment}" Width="300" TextWrapping="Wrap"
                                                Style="{StaticResource smallTitleStyle}">
                                        </TextBlock>              
                                     </ToolTip>
                                </TextBlock.ToolTip>
                            </TextBlock>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" VerticalAlignment="Center">
                            <TextBlock Grid.Row="0" Grid.Column="2" Margin="0,0,8,0"                               
                               Style="{StaticResource textStyleTextBlock}">Changed Fields : </TextBlock>
                            <TextBlock Grid.Row="0" Grid.Column="1" 
                        Text="{Binding Path=ChangedFields, Converter={StaticResource ChangedFieldCollectionToStringConverter}}" 
                        Style="{StaticResource smallTitleStyle}" ToolTipService.ShowDuration="10000" >                                
                                 <TextBlock.ToolTip>
                                <ToolTip DataContext="{Binding Path=PlacementTarget.DataContext, RelativeSource={RelativeSource Self}}">                                                                               
                                          <ListView ItemsSource="{Binding ChangedFields}" >
                                            <ListView.View>
                                                <GridView>
                                                    <GridViewColumn Header="Field Name" DisplayMemberBinding="{Binding Path=FieldName}"/>
                                                    <GridViewColumn Header="Previous Value" DisplayMemberBinding="{Binding Path=OldValue}" Width="200"/>
                                                    <GridViewColumn Header="Current Value" DisplayMemberBinding="{Binding Path=NewValue}" Width="200" />
                                                </GridView>
                                            </ListView.View>
                                        </ListView>
                                </ToolTip>
                                      </TextBlock.ToolTip>
                            </TextBlock>
                        </StackPanel>
                    </StackPanel>

                </Grid>
            </Border>            
        </DataTemplate>
        <DataTemplate x:Key="ChangedField">                        
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition></RowDefinition>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="150"></ColumnDefinition>
                    <ColumnDefinition Width="150"></ColumnDefinition>
                    <ColumnDefinition Width="150"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" Text="Test"></TextBlock>
            </Grid>
        </DataTemplate>
        <DataTemplate x:Key="workItemDetailsTemplate">
            <StackPanel Orientation="Vertical">
                <!--<WebBrowser x:Name="MyWebBrowser" Margin="0,0,8,0" Width="500"  Height="100" >
                    <WebBrowser.Tag>
                        <MultiBinding Converter="{StaticResource HtmlToDocumentConverter}" Mode="OneWay">
                            <Binding RelativeSource="{x:Static RelativeSource.Self}" />
                            <Binding Path="HistoryComment"/>
                        </MultiBinding>
                    </WebBrowser.Tag>
                </WebBrowser>-->
                <!--<TextBlock Text="{Binding Path=Owner.Name}"></TextBlock>
                <ListView ItemsSource="{Binding Source=ChangedFields}">
                    <ListView.View>
                        <GridView>
                            <GridViewColumn Header="Field Name" DisplayMemberBinding="{Binding Path=FieldName}"/>
                            <GridViewColumn Header="Previous Value" DisplayMemberBinding="{Binding Path=OldValue}"/>
                            <GridViewColumn Header="Current Value" DisplayMemberBinding="{Binding Path=NewValue}"/>
                        </GridView>
                    </ListView.View>
                </ListView>-->
            </StackPanel>
        </DataTemplate>

        <!--<Style TargetType="{x:Type ListBoxItem}">
            <Style.Triggers>
                <Trigger Property="Selector.IsSelected" Value="True">
                    <Setter Property="Background" Value="Moccasin" />
                </Trigger>
            </Style.Triggers>
        </Style>-->

        <DataTemplate x:Key="groupingHeaderTemplate">
            <TextBlock Text="{Binding Path=Name}"
                       Foreground="Navy" FontWeight="Bold" FontSize="12"/>
        </DataTemplate>

        <CollectionViewSource 
              Source="{Binding  Path=WorkItem.HistoryItems}"   
              x:Key="listingDataView" />

    </Control.Resources>
    <ScrollViewer>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="300"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="100"/>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        
        <TextBlock Grid.Row="0" Grid.Column="0"
                   Style="{StaticResource smallTitleStyle}" HorizontalAlignment="Left" Margin="8,10,8,8">Title:</TextBlock>
        <TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" TextWrapping="Wrap" HorizontalAlignment="Left" VerticalAlignment="Center" Style="{StaticResource textStyleTextBlock}" Text="{Binding  Path=WorkItem.Title}"/>

        <TextBlock Grid.Row="1" Grid.Column="0"
                   Style="{StaticResource smallTitleStyle}" HorizontalAlignment="Left" Margin="8,10,8,8">Assigned To:</TextBlock>
        <StackPanel Orientation="Vertical" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2">
            <controls:PresenceIndicator ContextualInformation="{Binding  Path=WorkItem.WorkItemContextualInformation}" Source="{Binding  Path=WorkItem.AssignedTo.IMSource}" PhotoDisplayMode="Small"  HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBlock Style="{StaticResource smallTitleStyle}" Text="{Binding  Path=WorkItem.AssignedTo.Name}"  HorizontalAlignment="Left" VerticalAlignment="Center"  TextTrimming="CharacterEllipsis" ToolTip="{Binding  Path=WorkItem.AssignedTo.Name}" Width="150"/>
        </StackPanel>

        <TextBlock Grid.Row="2" Grid.Column="0" HorizontalAlignment="Left"
                   Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">Created By:</TextBlock>
        <StackPanel Orientation="Vertical" Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Center" Grid.Column="1" Grid.ColumnSpan="2">
            <controls:PresenceIndicator ContextualInformation="{Binding  Path=WorkItem.WorkItemContextualInformation}"  Source="{Binding  Path=WorkItem.CreatedBy.IMSource}" PhotoDisplayMode="Small"  HorizontalAlignment="Left" VerticalAlignment="Center" />
            <TextBlock  Style="{StaticResource smallTitleStyle}" Text="{Binding  Path=WorkItem.CreatedBy.Name}"  HorizontalAlignment="Left" VerticalAlignment="Center" TextTrimming="CharacterEllipsis" ToolTip="{Binding  Path=WorkItem.CreatedBy.Name}" Width="150" />            
        </StackPanel>
        <TextBlock Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="3"
                   Style="{StaticResource titleStyle}" Margin="8,10,8,8">Work Item History</TextBlock>
        
        <ListBox x:Name="HistoryListBox" Grid.Row="4" Grid.ColumnSpan="3" Margin="8"
            ItemsSource="{Binding Source={StaticResource listingDataView}}">
            <ListBox.GroupStyle>
                <GroupStyle 
                  HeaderTemplate="{StaticResource groupingHeaderTemplate}"
                  />
            </ListBox.GroupStyle>
        </ListBox>
        <StackPanel Orientation="Horizontal" Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3">
            <TextBlock HorizontalAlignment="Left"
                   Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">Show history items where</TextBlock>
            <ComboBox x:Name="WorkItemFieldsSelection" ItemsSource="{Binding Path=WorkItemFields}" Height="20" Width="100" SelectedIndex="{Binding  Path=WorkItem.SelectedFieldIndex, Mode=TwoWay}" SelectionChanged="WorkItemFieldsSelection_SelectionChanged" />
            <TextBlock HorizontalAlignment="Left" Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">field has changed. (Showing </TextBlock>
            <TextBlock HorizontalAlignment="Left" Text="{Binding  Path=WorkItem.CurrentHistoryDisplayCount}" Style="{StaticResource smallTitleStyle}"></TextBlock>
            <TextBlock HorizontalAlignment="Left" Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">of </TextBlock>
            <TextBlock HorizontalAlignment="Left" Text="{Binding  Path=WorkItem.HistoryItems.Count}" Style="{StaticResource smallTitleStyle}"></TextBlock>
            <TextBlock HorizontalAlignment="Left" Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">)</TextBlock>
        </StackPanel>
        <StackPanel Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal" VerticalAlignment="Bottom" Visibility="{Binding  Path=WorkItem.IsUserLoading, Converter={StaticResource booleanToVisibilityConverter}}">
            <TextBlock Style="{StaticResource smallTitleStyle}" HorizontalAlignment="Left" Margin="8,10,8,8">Loading Users</TextBlock>        
            <ProgressBar IsIndeterminate="True" Width="200" Height="20"/>
        </StackPanel>
        <!--<Expander Header="Settings" Grid.Row="7" Grid.Column="0" Grid.ColumnSpan="3">
            <StackPanel Margin="10,4,0,0">
                <TextBlock HorizontalAlignment="Left" Style="{StaticResource smallTitleStyle}" Margin="8,10,8,8">Use TFS user DisplayName as lync contact search string, when</TextBlock>
                <RadioButton Margin="4" Content="Never" />                
                <RadioButton Margin="4" Content="if the user is not asssociated with the TFS project anymore" />
                <RadioButton Margin="4" Content="Always" />
            </StackPanel>
        </Expander>-->
    </Grid>
  </ScrollViewer>
</UserControl>
